package com.suning.sawp.member.esb;

import javax.annotation.Resource;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.suning.rsc.dto.responsedto.MbfServiceResponse;
import com.suning.rsc.mqservice.ei.annotation.EsbEIServerService;
import com.suning.rsc.server.NullResponseDto;
import com.suning.rsc.server.mq.MQServerServiceHandler;
import com.suning.sawp.dto.common.NsfNullReponseInterfaceForEsb;
import com.suning.sawp.dto.esb.DistributeEmployeeInfoReq;
import com.suning.sawp.member.service.MemCustomerService;
/**
 * 
 * 接收HR人员变动通知<br> 
 * 〈功能详细描述〉
 * UUMService-distributeEmployeeInfo
 * @author 12061818
 * @see [相关类/方法]（可选）
 * @since [产品/模块版本] （可选）
 */
@EsbEIServerService(connectionFactory = "snsawpConnectionFactory", receiveQueue = "distributeEmployeeInfoQueue")
public class EmployeeInfoDistributeListener extends MQServerServiceHandler<DistributeEmployeeInfoReq, NullResponseDto, NsfNullReponseInterfaceForEsb> {

    private static final Logger LOGGER = LoggerFactory.getLogger(EmployeeInfoDistributeListener.class);
    
    private static final String QUIT = "D";
    
    @Resource
    MemCustomerService memCustomerService;
    
    /**
     * 接受HR离职消息,处理离职员工客户为共享客户
     */
    @Override
    public NullResponseDto handleBizz(DistributeEmployeeInfoReq bizzRequestObject, String uid) {
        LOGGER.info("UUMService-distributeEmployeeInfo deal, uid={}", uid);
        if (null != bizzRequestObject && null != bizzRequestObject.getEmployeeInfo()
                && QUIT.equals(bizzRequestObject.getEmployeeInfo().getOperation())) {
            // 离职的员工处理
            String staffId = bizzRequestObject.getEmployeeInfo().getEmployeeId();
            LOGGER.info("UUMService-distributeEmployeeInfo staffId：{}", staffId);
            try {
                if (StringUtils.isNotBlank(staffId)) {
                    // 修改该员工的客户为共享客户
                    memCustomerService.updateToShareCustomer(staffId);
                }
            } catch (Exception e) {
                LOGGER.error("UUMService-distributeEmployeeInfo error, staffId=" + staffId, e);
            }
        }
        return null;
    }

    @Override
    public void sendResponse(NsfNullReponseInterfaceForEsb clientInterface, NullResponseDto response,
            MbfServiceResponse serviceResponse) {
        LOGGER.debug("");
    }

}
